package org.eking.bigdata.spark;

import java.io.Serializable;
import java.util.Arrays;
import java.util.Iterator;

import org.apache.spark.SparkConf;
import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.JavaSparkContext;
import org.apache.spark.api.java.function.FlatMapFunction;

public class TestSpark2 implements Serializable{

	public static void main(String[] args) {
		// 
		SparkConf conf = new SparkConf().setAppName("SparkTest");
		conf.setMaster("spark://10.71.88.13:7702");
		JavaSparkContext sc = new JavaSparkContext(conf);
		JavaRDD<String> distFile = sc.textFile("hdfs://10.71.88.13:9001/lele/spark4.txt");
		System.out.println(distFile.collect());
		JavaRDD<String> LineSplit = distFile.flatMap(new FlatMapFunction<String, String>() {
		      @Override
		      public Iterator<String> call(String s) {
		    	
		        return Arrays.asList(s.split("\\.")).iterator();
		      }
		});
		System.out.println(LineSplit.collect());
		JavaRDD<String> WordSplit = LineSplit.flatMap(new FlatMapFunction<String, String>() {
		      @Override
		      public Iterator<String> call(String s) {
		        return Arrays.asList(s.split(",")).iterator();
		      }
		});
		
		System.out.println(WordSplit.collect());
		System.out.println("well success" );
		
		sc.stop();
	}

}
